package com.lcq.study.leetcode.cjsf;

/**
 * @ClassName 初级算法第1章07题
 * @Description
 * @Author lichuanqi
 * @Date 2022/10/27 17:45
 * @Version 1.0
 **/
public class cjsf108gai {
    public static void main(String[] args) {
        cjsf108gai solution = new cjsf108gai();
        int[] ints = {0,1,0,3,6,0,2,5,12,0, 19, 10, 9};
        solution.moveZeroes(ints);
        for (int anInt : ints) {
            System.out.println(anInt);
        }
    }

    public void moveZeroes(int[] nums) {
        int length = nums.length;
        int s0 = -1;
        for (int i = 0; i < length; i++) {
            if (nums[i] == 0){
                if (s0 == -1){
                    s0 = i;
                }
            }else {
                if (s0 != -1){
                    swap(nums, s0, i);
                    s0++;
                }
            }
        }
    }

    public void swap(int[] nums, int a1, int a2){
        int tmp = nums[a1];
        nums[a1] = nums[a2];
        nums[a2] = tmp;
    }
}
